/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose : Definition of ME handler: ME (350) get priority to queue setting
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1) ME handler: me (350)
 */

#include "app_basic.h"
#include "feature_mgmt.h"

#define MIB_TABLE_ME350_ATTR_NUM            (17)
#define MIB_TABLE_ME350_ENTITYID_INDEX      ((MIB_ATTR_INDEX)1)
#define MIB_TABLE_ME350_NO1_ATTR		    ((MIB_ATTR_INDEX)2)
#define MIB_TABLE_ME350_NO2_ATTR		    ((MIB_ATTR_INDEX)3)
#define MIB_TABLE_ME350_NO3_ATTR		    ((MIB_ATTR_INDEX)4)
#define MIB_TABLE_ME350_NO4_ATTR		    ((MIB_ATTR_INDEX)5)
#define MIB_TABLE_ME350_NO5_ATTR		    ((MIB_ATTR_INDEX)6)
#define MIB_TABLE_ME350_NO6_ATTR		    ((MIB_ATTR_INDEX)7)
#define MIB_TABLE_ME350_NO7_ATTR		    ((MIB_ATTR_INDEX)8)
#define MIB_TABLE_ME350_NO8_ATTR		    ((MIB_ATTR_INDEX)9)
#define MIB_TABLE_ME350_NO9_ATTR		    ((MIB_ATTR_INDEX)10)
#define MIB_TABLE_ME350_NO10_ATTR		    ((MIB_ATTR_INDEX)11)
#define MIB_TABLE_ME350_NO11_ATTR		    ((MIB_ATTR_INDEX)12)
#define MIB_TABLE_ME350_NO12_ATTR		    ((MIB_ATTR_INDEX)13)
#define MIB_TABLE_ME350_NO13_ATTR		    ((MIB_ATTR_INDEX)14)
#define MIB_TABLE_ME350_NO14_ATTR		    ((MIB_ATTR_INDEX)15)
#define MIB_TABLE_ME350_NO15_ATTR		    ((MIB_ATTR_INDEX)16)
#define MIB_TABLE_ME350_NO16_ATTR		    ((MIB_ATTR_INDEX)17)


/* Table me 350 stucture */
typedef struct
{
    UINT16 EntityID;
    UINT32 no1;
    UINT16 no2;
    UINT16 no3;
    UINT16 no4;
    UINT16 no5;
    UINT16 no6;
    UINT8  no7;
    UINT32 no8;
    UINT8  no9[3];
    UINT8  no10;
    UINT8  no11;
    UINT8  no12;
    UINT8  no13;
    UINT32 no14;
    UINT8  no15[6];
    UINT16 no16;
} __attribute__((packed)) MIB_TABLE_ME350_T;


MIB_TABLE_INFO_T gMibMe350TableInfo;
MIB_ATTR_INFO_T gMibMe350AttrInfo[MIB_TABLE_ME350_ATTR_NUM];
MIB_TABLE_ME350_T gMibMe350DefRow;
MIB_TABLE_OPER_T gMibMe350Oper;

GOS_ERROR_CODE omci_mib_me_350_oper_reset(UINT32 args_num, ...)
{
    MIB_TABLE_ME350_T me350;

    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me350");


    remove(OMCI_NTP_DATE_TIME_CONF);

    remove(OMCI_NTP_DATE_TIME_TMP_CONF);

    MIB_Default(MIB_TABLE_ME350_INDEX, &me350, sizeof(MIB_TABLE_ME350_T));

    me350.EntityID = 0x0;
    me350.no1 = 0x00020102;
    me350.no2 = 0x0000;
    me350.no3 = 0x0000;
    me350.no4 = 0x0258;
    me350.no5 = 0x0100;
    me350.no6 = 0x0000;
    me350.no7 = 0x00;
    me350.no8 = 0x00000000;
    me350.no9[0] = 0x00;
    me350.no9[1] = 0x00;
    me350.no9[2] = 0x00;
    me350.no10 = 0x00;
    me350.no11 = 0x00;
    me350.no12 = 0x00;
    me350.no13 = 0x00;
    me350.no14 = 0x01080108;
    me350.no15[0] = 0x05;
    me350.no15[1] = 0x39;
    me350.no15[2] = 0x77;
    me350.no15[3] = 0x05;
    me350.no15[4] = 0x39;
    me350.no15[5] = 0x77;
    me350.no16 = 0x00;


    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME350_INDEX, &me350, sizeof(MIB_TABLE_ME350_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME350_INDEX, NULL, &me350, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME350_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    return GOS_OK;
}

GOS_ERROR_CODE HwMe350DrvCfg(void           *pOldRow,
                            void            *pNewRow,
                            MIB_OPERA_TYPE  operationType,
                            MIB_ATTRS_SET   attrSet,
                            UINT32          pri)
{
	MIB_TABLE_ME350_T     *pMibHwMe350 = NULL, *pOldMibHwMe350 = NULL;
    FILE                  *fp = NULL;
    UINT8                 month = 0, day = 0, h = 0, m = 0, s = 0;
    UINT16                year = 0;
    UINT32                strLen;
    omci_event_msg_t        omciEventMsg;

	pMibHwMe350 = (MIB_TABLE_ME350_T *)pNewRow;
    pOldMibHwMe350 = (MIB_TABLE_ME350_T *)pOldRow;

    OMCI_LOG(OMCI_LOG_LEVEL_DBG, "Start %s sec=%u...", __FUNCTION__, s);

    switch (operationType)
    {
    case MIB_SET:
    	OMCI_LOG(OMCI_LOG_LEVEL_DBG,"HW ME 350 --> SET");

        if (!MIB_IsInAttrSet(&attrSet, MIB_TABLE_ME350_NO8_ATTR) &&
            !MIB_IsInAttrSet(&attrSet, MIB_TABLE_ME350_NO9_ATTR))
            return GOS_OK;

        if (access(OMCI_NTP_DATE_TIME_CONF, 0) < 0)
        {
            // doesn't exist

            if (!(fp = fopen (OMCI_NTP_DATE_TIME_CONF, "w")))
            {
                OMCI_LOG(OMCI_LOG_LEVEL_ERR, "fopen %s failed", OMCI_NTP_DATE_TIME_CONF);
                return GOS_FAIL;

            }
            if (pMibHwMe350->no8 != pOldMibHwMe350->no8)
            {
                year = (((pMibHwMe350->no8) & 0xFFFF0000) >> 16);
                month = (((pMibHwMe350->no8) & 0xFF00) >> 8);
                day = ((pMibHwMe350->no8) & 0xFF);
            }

            if (pMibHwMe350->no9[0] != pOldMibHwMe350->no9[0])
            {
                h = pMibHwMe350->no9[0];
            }
            if (pMibHwMe350->no9[1] != pOldMibHwMe350->no9[1])
            {
                m = pMibHwMe350->no9[1];
            }

            if (pMibHwMe350->no9[2] != pOldMibHwMe350->no9[2])
            {
                s = pMibHwMe350->no9[2];
            }

            //DATE=MMDDHHMMSSYYYY
            fprintf(fp, "%s", "ENABLE_NTP_SERVER=0\n");
            fprintf(fp, "DATE=%02u%02u%02u%02u%04u\n", month, day, h, m, year);
            fclose(fp);
        }
        else
        {

            if (MIB_IsInAttrSet(&attrSet, MIB_TABLE_ME350_NO8_ATTR) ||
                MIB_IsInAttrSet(&attrSet, MIB_TABLE_ME350_NO9_ATTR))
            {
                CHAR *pStr = NULL;
                if (GOS_OK != omci_util_ntp_conf_replace_opt_val("ENABLE_NTP_SERVER", "=0"))
                {
                    OMCI_LOG(OMCI_LOG_LEVEL_ERR, "%s():%d, Failed to replace option value of ntp conf",
                                __FUNCTION__, __LINE__);
                    return GOS_FAIL;
                }

                year = (((pMibHwMe350->no8) & 0xFFFF0000) >> 16);
                month = (((pMibHwMe350->no8) & 0xFF00) >> 8);
                day = ((pMibHwMe350->no8) & 0xFF);
                h = pMibHwMe350->no9[0];
                m = pMibHwMe350->no9[1];
                s = pMibHwMe350->no9[2];

                strLen = snprintf(NULL, 0, "=%02u%02u%02u%02u%04u\n", month, day, h, m, year);
                pStr = (CHAR *)malloc(strLen + 1);
                snprintf(pStr, strLen + 1, "=%02u%02u%02u%02u%04u", month, day, h, m, year);
                if (GOS_OK != omci_util_ntp_conf_replace_opt_val("DATE", pStr))
                {
                    OMCI_LOG(OMCI_LOG_LEVEL_ERR, "Failed to replace option value of ntp conf");
                    free(pStr);
                    return GOS_FAIL;
                }
                free(pStr);
            }
        }

        // send notification
        memset(&omciEventMsg, 0, sizeof(omci_event_msg_t));
        omciEventMsg.subType = OMCI_EVENT_TYPE_NTP_DATETIME;
        omciEventMsg.status = 1;

        if (GOS_OK != omci_wrapper_sendOmciEvent(&omciEventMsg))
        {
            OMCI_LOG(OMCI_LOG_LEVEL_ERR, "Send ntp event fail");
        }
    	break;
    default:
        break;
    }

	return GOS_OK;
}


GOS_ERROR_CODE mibTable_init ( MIB_TABLE_INDEX tableId )
{
    UINT8 proprietary_mib_cb_bitmask = 0;
    MIB_TABLE_ME350_INDEX = tableId;
    memset(&(gMibMe350Oper), 0x0, sizeof(MIB_TABLE_OPER_T));

	if (FAL_ERR_NOT_REGISTER == feature_api_is_registered(FEATURE_API_BDP_00000200))
    {
        return GOS_FAIL;
    }

    gMibMe350TableInfo.Name = "HW ME350";
    gMibMe350TableInfo.ShortName = "HW350";
    gMibMe350TableInfo.Desc = "huawei ME350";
    gMibMe350TableInfo.ClassId = (UINT32)(350);
    gMibMe350TableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_ONU);
    gMibMe350TableInfo.StdType = (UINT32)(OMCI_ME_TYPE_PROPRIETARY);
    gMibMe350TableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_SET | OMCI_ME_ACTION_GET);
    gMibMe350TableInfo.pAttributes = &(gMibMe350AttrInfo[0]);
    gMibMe350TableInfo.attrNum = MIB_TABLE_ME350_ATTR_NUM;
    gMibMe350TableInfo.entrySize = sizeof(MIB_TABLE_ME350_T);
    gMibMe350TableInfo.pDefaultRow = &gMibMe350DefRow;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityID";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].Name = "First";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].Name = "Second";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].Name = "Third";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].Name = "4";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].Name = "5";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].Name = "6";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].Name = "7";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].Name = "8";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].Name = "9";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].Name = "10";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].Name = "11";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].Name = "12";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].Name = "13";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].Name = "14";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].Name = "15";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].Name = "16";

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "First";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Second";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Third";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Forth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Fifth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Sixth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Seventh";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Eighth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Ninth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Tenth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Eleventh";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Twelfth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Thirteenth";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Fourteen";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Fifteen";
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Sixteen";

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_STR;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT32;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_STR;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].Len = 3;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].Len = 1;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].Len = 4;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].Len = 6;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibMe350AttrInfo[MIB_TABLE_ME350_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO1_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO2_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO3_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO4_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO5_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO6_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO7_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO8_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO9_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO10_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO11_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO12_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO13_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO14_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO15_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe350AttrInfo[MIB_TABLE_ME350_NO16_ATTR - MIB_TABLE_FIRST_INDEX].OptionType =OMCI_ME_ATTR_TYPE_MANDATORY;

    gMibMe350Oper.meOperCb[PROPRIETARY_MIB_CB_RESET] = omci_mib_me_350_oper_reset;
    gMibMe350Oper.meOperDump = omci_mib_oper_dump_default_handler;

	gMibMe350Oper.meOperDrvCfg = HwMe350DrvCfg;
    proprietary_mib_cb_bitmask = (1 << PROPRIETARY_MIB_CB_RESET);


    MIB_InfoRegister(tableId, &gMibMe350TableInfo, &gMibMe350Oper);
    MIB_RegisterCallback(tableId, NULL, NULL);

    MIB_Proprietary_Reg(tableId, proprietary_mib_cb_bitmask);

    return GOS_OK;
}
